require.config({
    baseUrl: baseUrl
});
define(function(require){
    var $ = require('jquery');
    window.$ = window.jQuery = $;

    var c=require('../common');
    var dialog=require('bDialog/dialog');
    window.dialog=dialog;


    $(function(){
        c.init();

        $('#verifyimg').click(function(){ 
            var date = new Date();
            var ttime = date.getTime();
            var url = URL+"/verify";
            $(this).attr('src', url + '/' + ttime);
        });
        // 绑定回车事件
        $(this).bind('keydown', function(e) {
            var key = e.which;
            if (key == 13) { doLogin(); }
        });
        $("#login_verify").keyup(function(){
            if($('#login_verify').val().length>=4){
                chkverify();
            }
        });
        $('#doLogin').click(function(){
            doLogin();
        });

        function chkverify(){
            var vcode = $.trim($('#login_verify').val());
            var chkjg=true;
            var url = URL+"/checkverify/verify/"+vcode;
            $.ajax({url : url,async: false,cache: false, type : "get",dataType : 'json',
                success : function(data) {
                    if(data.status==0){
                        $(".tipsinfo").html('验证码有误！');
                        chkjg=false;
                    }else{
                        $(".tipsinfo").html('验证码正确！');
                    }
                }
            });
            return chkjg;
        }

        function doLogin(){
            var uname = $('#login_name');
            var upass = $('#login_pwd');
            var vcode = $('#login_verify');

            var mreg = /^1[358]\d{9}$/;
            var ereg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

            if($.trim(uname.val())==''){
                $(".tipsinfo").html('请输入登录账号！');
                uname.addClass("s-txt-focus").focus(); return false;
            }
            if($.trim(upass.val())==''){
                $(".tipsinfo").html('请输入登录密码！');
                upass.addClass("s-txt-focus").focus(); return false;
            }else{
                upass.removeClass("s-txt-focus");
            }
            if($.trim(vcode.val()) == ''){
                $(".tipsinfo").html('请输入验证码！');
                vcode.addClass("s-txt-focus").focus(); return false;
            }
            if(chkverify()==false){return false;}
            $.ajax({ async: false,cache: false,type: 'POST',dataType: 'json',
                url:URL+'/checkLogin',
                data:{'account':$.trim(uname.val()),'password':$.trim(upass.val()),'verify':$.trim(vcode.val())},
                success:function(data){
                    if(data.status==1){
                        location.href = data.url;//直接跳转到相应首页
                    }else{
                        $(".tipsinfo").html(data.info);
                    }
                }
            });
        }


    });
});